<template>
  <!--修改电子邮箱-->
  <div class="page">
    <el-form :model="changeEmailNum" ref="EmailNum" label-width="100px">
      <el-form-item prop="newEmailNum" label="电子邮箱" :rules="[
      { required: true,type:'email', message: '请输入电子邮箱', trigger: 'blur' }
      ]">
        <el-input style="float:left" v-model="changeEmailNum.newEmailNum"></el-input>
      </el-form-item>
      <el-form-item prop="remark" label="修改说明" :rules="[
      { required: true, message: '请输入修改说明', trigger: 'blur' }
      ]">
        <el-input type="textarea" v-model="changeEmailNum.remark"></el-input>
      </el-form-item>
    </el-form>
    <el-button @click="changeEmailConfirm">确 定</el-button>
    <el-button @click="changeEmailConcle">取 消</el-button>
  </div>
</template>
<script>
  import net from '@/util/net'
  import servers from '@/config/servers'
  export default {
    name: 'modify-email',
    data() {
      return {
        // 修改邮箱
        changeEmailNum: {
          remark: '',
          newEmailNum: ''
        }
      }
    },
    methods: {
      /**
       * 修改电子邮箱确定
       */
      changeEmailConfirm() {
        this.$refs['EmailNum'].validate((valid) => {
          if (!valid) {
            return false
          }
          this.changeEmailNum.custId = this.$store.state.accManage.cust_id
          net.send({
            server: servers.AccManage.modify_phone_email_info,
            data: {
              custId: this.changeEmailNum.custId,
              newEmailNum: this.changeEmailNum.newEmailNum,
              remark: this.changeEmailNum.remark
            }
          }).then((data) => {
            this.$message({
              type: 'success',
              message: '修改成功'
            })
            // 新邮箱地址
            this.$emit('updateEmail', this.changeEmailNum.newEmailNum)
            // 重置
            this.$refs['EmailNum'].resetFields()
            // 刷新修复信息
            this.$emit('refreshRepairInfo')
            //   关闭修改电子邮箱dialog
            this.$emit('close')
          }, err => {
            this.$message({
              type: 'info',
              message: err.reason
            })
          })
        })
      },
      /**
       * 取消修改电子邮箱
       */
      changeEmailConcle() {
        //   关闭修改电子邮箱dialog
        this.$emit('close')
        // 重置
        this.$refs['EmailNum'].resetFields()
      }
    }
  }

</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>


</style>
